/**
 * 
 */
package com.yidu.drug.service.impl;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yidu.drug.dao.FdPurchaseModelMapper;
import com.yidu.drug.model.FdPurchaseModel;
import com.yidu.drug.service.FdPurchaseService;

/**
 * @author yuanwei
 *
 */
@Service
public class FdPurchaseServiceImpl implements FdPurchaseService{

	@Resource
	private FdPurchaseModelMapper FdPurchaseModelMapperDao;
	
	/**
	 * 查询订单表中所有的数据
	 */
	@Override
	public List<FdPurchaseModel> findAll(FdPurchaseModel fdPurchaseModel,int page,int limit) {
		List<FdPurchaseModel> list=FdPurchaseModelMapperDao.findAll(fdPurchaseModel,page,limit);
		for (FdPurchaseModel fdPurchaseModel1 : list) {
			int one=Integer.valueOf(fdPurchaseModel1.getFdPoState());
			if(one==0){
				fdPurchaseModel1.setFdPoState("审核失败");
			}else if(one==1){
				fdPurchaseModel1.setFdPoState("等待审核");
			}else if(one==2){
				fdPurchaseModel1.setFdPoState("财务审核成功.等待总经理审核");
			}else if(one==3){
				fdPurchaseModel1.setFdPoState("审核成功");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchaseModel1.getFdPoTime());
	        fdPurchaseModel1.setFdPoTimes(sjian);
		}
		return list;
	}

	/**
	 * 根据id删除数据
	 */
	@Override
	public int delete(String fdPoId) {
		
		return FdPurchaseModelMapperDao.deleteByPrimaryKey(fdPoId);
	}

	/**
	 * 根据id查询数据
	 */
	@Override
	public FdPurchaseModel findById(String fdPoId) {
		
		return FdPurchaseModelMapperDao.selectByPrimaryKey(fdPoId);
	}

	/**
	 * 根据id修改数据
	 */
	@Override
	public int update(FdPurchaseModel fdPurchaseModel) {
		
		return FdPurchaseModelMapperDao.updateByPrimaryKeySelective(fdPurchaseModel);
	}
	
	/**
	 * 新增订单
	 */
	@Override
	public int save(FdPurchaseModel fdPurchaseModel) {
		
		return FdPurchaseModelMapperDao.insertSelective(fdPurchaseModel);
	}

	@Override
	public Integer findRows(FdPurchaseModel fdPurchaseModel) {
		
		return FdPurchaseModelMapperDao.findRows(fdPurchaseModel);
	}

	/**
	 *  根据id修改价格和数量
	 */
	@Override
	public int updates(Long fdSunnum, BigDecimal fdSumprice, String fdPoId) {
		
		return FdPurchaseModelMapperDao.updates(fdSunnum, fdSumprice, fdPoId);
	}
	/**
	 * 分店财务审核(分店退货)
	 */
	@Override
	public List<FdPurchaseModel> findAllPage(Map<String, String> map) {
		List<FdPurchaseModel> list =FdPurchaseModelMapperDao.findAllPage(map);
		for (FdPurchaseModel fdPurchase : list) {
			int ones=Integer.valueOf(fdPurchase.getFdPoState());
		    if(ones==2){
				fdPurchase.setFdPoState("等待分店财务审核");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchase.getFdPoTime());
	        fdPurchase.setFdPoTimes(sjian);
		}
		return list;
	}
	
	/**
	 * 采购订单查询和条件查询
	 */
	@Override
	public List<FdPurchaseModel> findAllPages(Map<String, String> map) {
		List<FdPurchaseModel> list =FdPurchaseModelMapperDao.findAllPages(map);
		for (FdPurchaseModel fdPurchaseModel1 : list) {
			int one=Integer.valueOf(fdPurchaseModel1.getFdPoState());
			if(one==0){
				fdPurchaseModel1.setFdPoState("审核失败");
			}else if(one==1){
				fdPurchaseModel1.setFdPoState("等待审核");
			}else if(one==2){
				fdPurchaseModel1.setFdPoState("财务审核成功.等待总经理审核");
			}else if(one==3){
				fdPurchaseModel1.setFdPoState("审核成功");
			}else if(one==5){
				fdPurchaseModel1.setFdPoState("等待退货审核");
			}else if(one==6){
				fdPurchaseModel1.setFdPoState("退货分店财务审核成功，等待总店财务审核");
			}else if(one==7){
				fdPurchaseModel1.setFdPoState("退货总店财务审核成功，等待总店总经理审核");
			}else if(one==8){
				fdPurchaseModel1.setFdPoState("退货总店总经理审核成功");
			}else if(one==4){
				fdPurchaseModel1.setFdPoState("退货审核失败");
			}else if(one==9){
				fdPurchaseModel1.setFdPoState("订单已被总店驳回");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchaseModel1.getFdPoTime());
	        fdPurchaseModel1.setFdPoTimes(sjian);
		}
		return list;
	}

	/**
	 * 
	 * 采购订单查询行数
	 */
	@Override
	public int findTotalRows(Map<String, String> map) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.findTotalRows(map);
	}
	/**
	 * 修改分店的状态
	 */
	@Override
	public int updateFdPoState(String fdPoId,String fdPoState) {
		
		return FdPurchaseModelMapperDao.updateFdPoState(fdPoId,fdPoState);
	}

	@Override
	public int updateByPrimaryKeySelective(FdPurchaseModel record) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(FdPurchaseModel record) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.updateByPrimaryKey(record);
	}
	/**
	 * 总店总经理审核(分店退货)
	 */
	@Override
	public List<FdPurchaseModel> findAllPagess(Map<String, String> map) {
		List<FdPurchaseModel> list =FdPurchaseModelMapperDao.findAllPagess(map);
		for (FdPurchaseModel fdPurchase : list) {
			int ones=Integer.valueOf(fdPurchase.getFdPoState());
		    if(ones==9){
				fdPurchase.setFdPoState("总店财务审核成功.等待总店总经理审核");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchase.getFdPoTime());
	        fdPurchase.setFdPoTimes(sjian);
		}
		return list;
	}
	
	/**
	 * 总店总经理审核(分店退货)
	 */
	@Override
	public Object findRowss(FdPurchaseModel fdPurchase) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.findRowss(fdPurchase);
	}

	/**
	 * 审核查询数据和条件查询
	 */
	@Override
	public List<FdPurchaseModel> findAllshenhe(Map<String, String> paramMap) {
		List<FdPurchaseModel> list =FdPurchaseModelMapperDao.findAllshenhe(paramMap);
		for (FdPurchaseModel fdPurchaseModel1 : list) {
			int one=Integer.valueOf(fdPurchaseModel1.getFdPoState());
			if(one==1){
				fdPurchaseModel1.setFdPoState("等待审核");
			}else if(one==2){
				fdPurchaseModel1.setFdPoState("财务已审核，等待总经理审核");
			}else if(one==9){
				fdPurchaseModel1.setFdPoState("订单已被总店驳回");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchaseModel1.getFdPoTime());
	        fdPurchaseModel1.setFdPoTimes(sjian);
		}
		return list;
	}

	/**
	 * 审核查询行数
	 */
	@Override
	public int findAllshenheRows(Map<String, String> map) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.findAllshenheRows(map);
	}

	@Override
	public FdPurchaseModel findByfdPoId(String fdPoId) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.findByfdPoId(fdPoId);
	}
	/**
	 * 总店财务审核(分店退货)
	 */
	@Override
	public List<FdPurchaseModel> findZdCwAll(Map<String, String> map) {
		List<FdPurchaseModel> list =FdPurchaseModelMapperDao.findZdCwAll(map);
		for (FdPurchaseModel fdPurchase : list) {
			int ones=Integer.valueOf(fdPurchase.getFdPoState());
		    if(ones==8){
				fdPurchase.setFdPoState("分店财务审核成功.等待总店财务审核");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchase.getFdPoTime());
	        fdPurchase.setFdPoTimes(sjian);
		}
		return list;
	}
	/**
	 * 总店财务审核(分店退货)
	 */
	@Override
	public Object findZdCwRow(FdPurchaseModel fdPurchase) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.findZdCwRow(fdPurchase);
	}
	/**
	 * 采购显示所有--退货
	 * @param map
	 * @return
	 */
	@Override
	public List<FdPurchaseModel> findAlls(Map<String, String> map) {
		List<FdPurchaseModel> list =FdPurchaseModelMapperDao.findAlls(map);
		for (FdPurchaseModel fdPurchase : list) {
			int one=Integer.valueOf(fdPurchase.getFdPoState());
			if(one==5){
				fdPurchase.setFdPoState("等待审核");
			}else if(one==6){
				fdPurchase.setFdPoState("分店财务审核成功，等待总店财务审核");
			}else if(one==7){
				fdPurchase.setFdPoState("总店财务审核成功，等待总店总经理审核");
			}else if(one==8){
				fdPurchase.setFdPoState("总店总经理审核成功");
			}else if(one==4){
				fdPurchase.setFdPoState("审核失败");
			}
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        String sjian = sdf.format(fdPurchase.getFdPoTime());
	        fdPurchase.setFdPoTimes(sjian);
		}
		return list;
	}
	/**
	 * 采购显示所有--退货
	 * @param map
	 * @return
	 */
	@Override
	public Object findRows(Map<String, String> map) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.findRows(map);
	}

	
	/**
	 * 根据采购Id修改审核状态(重新审核)
	 * @param pfId
	 * @return
	 */
	@Override
	public int updateByFdPoId(String fdPoId) {
		// TODO Auto-generated method stub
		return FdPurchaseModelMapperDao.updateByFdPoId(fdPoId);
	}

	
	
	
	

	
	

	
}
